//
//  MineCell.m
//  收纳
//
//  Created by  on 2022/10/27.
//

#import "MineCell.h"
@interface MineCell()
@property (strong, nonatomic) IBOutlet UISwitch *switchBtn;
@property (strong, nonatomic) IBOutlet UIButton *deleteBtn;
@property (strong, nonatomic) IBOutlet UIImageView *arrow;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *inputRight;

@end
@implementation MineCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.type = MineCellTypeDefault;
    self.switchBtn.onTintColor = Hex(@"#F6E66A");
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}
- (IBAction)actionForBtn:(UIButton *)sender {
    if (self.block) {
        self.block(NO);
    }
}
- (IBAction)actionForSth:(UISwitch *)sender {
    if (self.block) {
        self.block(sender.on);
    }
}

- (void)setType:(MineCellType)type{
    _type = type;
    NSString *key = [[self.dict allKeys] firstObject];
    if (key || key.length > 0) {
        self.title.text = key;
    }
    switch (type) {
        case MineCellTypeDefault:
            self.arrow.hidden = NO;
            self.input.hidden = NO;
            self.input.enabled = NO;
            self.switchBtn.hidden = YES;
            self.deleteBtn.hidden = YES;
            self.inputRight.constant = 14 + 14;
            self.input.text = [NSString stringWithFormat:@"%@",self.dict[key]==nil?@"":self.dict[key]];
            break;
        case MineCellTypeDelete:
            self.arrow.hidden = YES;
            self.input.hidden = YES;
            self.switchBtn.hidden = YES;
            self.deleteBtn.hidden = NO;
            self.inputRight.constant = 28;
            self.input.text = @"";
            break;
        case MineCellTypeSwitch:
            self.arrow.hidden = YES;
            self.input.hidden = YES;
            self.switchBtn.hidden = NO;
            self.deleteBtn.hidden = YES;
            self.inputRight.constant = 28;
            self.input.text = @"";
            self.switchBtn.on = [self.dict[key] boolValue];
            break;
        case MineCellTypeInput:
            self.arrow.hidden = YES;
            self.input.hidden = NO;
            self.input.enabled = YES;
            self.switchBtn.hidden = YES;
            self.deleteBtn.hidden = YES;
            self.inputRight.constant = 14;
            self.input.text = [NSString stringWithFormat:@"%@",self.dict[key]==nil?@"":self.dict[key]];
            break;
        case MineCellTypeNothing:
            self.arrow.hidden = YES;
            self.input.hidden = YES;
            self.switchBtn.hidden = YES;
            self.deleteBtn.hidden = YES;
            self.inputRight.constant = 28;
            self.input.text = @"";
            break;
        default:
            break;
    }
    
    
}
@end
